<template>
	<view class="bind-phone">
		<tui-modal :show="showModal"  custom>
			<view class="title">
				绑定手机号
			</view>
			<!-- <uni-forms ref="form" :modelValue="formData" :rules="rules">
				<uni-forms-item label="姓名" name="name">
					<uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
				</uni-forms-item>
				<uni-forms-item required :name="['data','hobby']" label="兴趣爱好">
					<uni-data-checkbox multiple v-model="formData.data.hobby" :localdata="hobby" />
				</uni-forms-item>
			</uni-forms> -->
			<form @submit="formSubmit" @reset="formReset">
				<tui-list-cell :hover="false">
					<view class="tui-line-cell">
						<view class="tui-title"><span class="star">*</span>手机号:</view>
						<input placeholder-class="tui-phcolor" class="tui-input" name="phone" placeholder="请输入手机号"
							maxlength="50" type="text" />
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false">
					<view class="tui-line-cell">
						<view class="tui-title">&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码:</view>
						<input password placeholder-class="tui-phcolor" class="tui-input" name="password"
							placeholder="请输入密码" maxlength="50" type="text" />
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false">
					<view class="tui-line-cell">
						<view class="tui-title"><span class="star">*</span>验证码:</view>
						<input placeholder-class="tui-phcolor" class="tui-input" name="code" placeholder="请输入验证码"
							maxlength="50" type="text" />
					</view>
				</tui-list-cell>
				<view class="btn">
					<tui-button height="62rpx" :size="28" type="gray" plain shape="circle" formType="reset"
						style="margin-right: 30rpx;">取消</tui-button>
					<tui-button height="62rpx" :size="28" type="danger" plain shape="circle"
						formType="submit">确定</tui-button>
				</view>
			</form>
		</tui-modal>
	</view>
</template>

<script>
	// data 数据 及 方法
	import form from "@/components/common/tui-validation/tui-validation.js"
	export default {
		props: {
			showModal: {
				type: Boolean,
				default: false,

			}
		},
		data() {
			return {
				formData: {
					name: '',
				},
				rules: [{
					name: "phone",
					rule: ["required", ],
					// "isMobile"  "请输入正确的手机号"
					msg: ["请输入手机号",]
				}, {
					name: "code",
					rule: ["required"],
					msg: ["请输入验证码"]
				}],
			}
		},
		methods: {
			formSubmit(e) {
				let formData = e.detail.value;
				let userInfo = JSON.parse(localStorage.getItem('userInfo'))
				formData._id = userInfo._id

				// //校验
				let checkRes = form.validation(formData, this.rules);
				if (!checkRes) {
					// uni.showToast({
					// 	title: "验证通过!",
					// 	icon: "none"
					// });
					this.http.post('BindUser', formData).then(res => {
						console.log(123, res);
						
						// this.formReset()
					})

				} else {
					//校验失败 checkRes 为错误信息
					uni.showToast({
						title: checkRes,
						icon: "none"
					});
				}
			},
			formReset(e) {
				this.$emit('close', false)
			},
			
			handleClick(e) {
				let index = e.index;
				console.log(123, e);
				// if (index === 0) {
				// 	this.tui.toast('你点击了取消按钮');
				// } else {
				// 	this.tui.toast('你点击了确定按钮');
				// }
				this.hideModal();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		font-size: 34rpx;
		text-align: center;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.star {
		color: red;
		margin-right: 5rpx;
	}

	.btn {
		display: flex;
		justify-content: space-between;
		margin-top: 24rpx;
	}

	.tui-line-cell {
		width: 100%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.tui-title {
		line-height: 32rpx;
		min-width: 120rpx;
		flex-shrink: 0;
	}

	.tui-input {
		font-size: 32rpx;
		color: #333;
		padding-left: 20rpx;
		flex: 1;
		overflow: visible;
	}

	.tui-btn-box {
		padding: 40rpx 30rpx;
		box-sizing: border-box;
	}

	.tui-button-gray {
		margin-top: 30rpx;
	}
</style>